package com.xlhj.boot.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: liucaijing
 * @description: ResultData
 * @date: 2021/6/14 7:40
 */
@Data
public class ResultData {

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回数据
     */
    private Map<String, Object> data = new HashMap<String, Object>();

    /**
     * 返回成功静态方法
     * @return
     */
    public static ResultData success() {
        ResultData result = new ResultData();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMessage(ResultEnum.SUCCESS.getMessage());
        return result;
    }

    /**
     * 返回失败静态方法
     * @return
     */
    public static ResultData fail() {
        ResultData result = new ResultData();
        result.setCode(ResultEnum.FAIL.getCode());
        result.setMessage(ResultEnum.FAIL.getMessage());
        return result;
    }

    public ResultData code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResultData message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResultData data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public ResultData data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }
}
